package cn.lastcrdg.testslide;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import java.util.List;

/**
 * author：liluo
 * e-mail：lastcrazysun@163.com
 * company：cusc
 * date：2017/10/12 13:38
 * description：
 */

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {

    private MyViewHolder mHolder;
    private List<String[]> list;
    private boolean isTwoData;

    public MyAdapter(List<String[]> list, boolean isTwoData) {
        this.list = list;
        this.isTwoData = isTwoData;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mHolder = new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_adapter, parent, false));
        return mHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        mHolder.tv1.setText(list.get(position)[0]);
        mHolder.tv2.setText(list.get(position)[1]);
        mHolder.tv3.setText(list.get(position)[2]);
        mHolder.tv4.setText(list.get(position)[3]);
        mHolder.tv5.setText(list.get(position)[4]);
        mHolder.tv6.setText(list.get(position)[5]);
        if (position + 1 == getItemCount()) {
            if (isTwoData) {
                mHolder.mLinearLayout.setVisibility(View.VISIBLE);
                mHolder.tv12.setText(list.get(position)[6]);
                mHolder.tv22.setText(list.get(position)[7]);
                mHolder.tv32.setText(list.get(position)[8]);
                mHolder.tv42.setText(list.get(position)[8]);
                mHolder.tv52.setText(list.get(position)[10]);
                mHolder.tv62.setText(list.get(position)[11]);
            } else {
                mHolder.mLinearLayout.setVisibility(View.GONE);
            }
        }else {
            mHolder.mLinearLayout.setVisibility(View.VISIBLE);
            mHolder.tv12.setText(list.get(position)[6]);
            mHolder.tv22.setText(list.get(position)[7]);
            mHolder.tv32.setText(list.get(position)[8]);
            mHolder.tv42.setText(list.get(position)[8]);
            mHolder.tv52.setText(list.get(position)[10]);
            mHolder.tv62.setText(list.get(position)[11]);
        }
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView tv1;
        private TextView tv2;
        private TextView tv3;
        private TextView tv4;
        private TextView tv5;
        private TextView tv6;
        private TextView tv12;
        private TextView tv22;
        private TextView tv32;
        private TextView tv42;
        private TextView tv52;
        private TextView tv62;
        private LinearLayout mLinearLayout;
        private ScrollView mScroll;

        public MyViewHolder(View view) {
            super(view);
            tv1 = view.findViewById(R.id.tv1);
            tv2 = view.findViewById(R.id.tv2);
            tv3 = view.findViewById(R.id.tv3);
            tv4 = view.findViewById(R.id.tv4);
            tv5 = view.findViewById(R.id.tv5);
            tv6 = view.findViewById(R.id.tv6);
            tv12 = view.findViewById(R.id.tv12);
            tv22 = view.findViewById(R.id.tv22);
            tv32 = view.findViewById(R.id.tv32);
            tv42 = view.findViewById(R.id.tv42);
            tv52 = view.findViewById(R.id.tv52);
            tv62 = view.findViewById(R.id.tv62);
            mLinearLayout = view.findViewById(R.id.ll_second);
            mScroll = view.findViewById(R.id.sv);
        }
    }
}
